<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="/dateUtil"  prefix="dateUtil"%>

<c:if test="${empty requestScope.records }">
		<center><h1>没有交易记录</h1></center>
</c:if>
<c:if test="${!empty requestScope.records }">
<!-- 资源管理模块 -->
<div role="tabpanel" class="tab-pane active" id="sour">
	<div class="check-div form-inline">
		<button class="btn btn-yellow btn-xs" data-toggle="modal" data-target="#addDiv" onclick='setType(1)'>新建支出</button>
		<button class="btn btn-yellow btn-xs" data-toggle="modal" data-target="#addDiv" onclick='setType(0)'>新建收入</button>
		<label>当前余额为${balance }</label><br>
	</div>
	<div class="data-div">
		<div class="row tableHeader">
			<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 ">
				交易id
 			</div>
 			<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
				交易说明
			</div>
			<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
				交易数额
			</div>
			<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
				账户余额
			</div>
			<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
				交易时间
			</div>
		</div>
		<div class="tablebody">
			<div id="collapseAccount" class="collapse in" aria-expanded="true">
				<c:forEach items="${requestScope.records }" var="record">
	 				<div class="row">
						<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 levl1 ">${record.id}
						</div>
						<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 levl1 ">${record.name}
						</div>
						<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 levl1 ${record.transfer>0?'pos':'neg' }">${record.transfer>0?'+':' ' }${record.transfer }
						</div>
						<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 levl1 ">${record.balance}
						</div>
						<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 levl1 ">${dateUtil:datetime2str(record.time) }
						</div>
	 				</div>
	 			</c:forEach>
			</div>
		</div>
	</div>
</div>
</c:if>
<!-- 添加支出菜单 -->
<div class="modal fade" id="addDiv" role="dialog" aria-labelledby="gridSystemModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="gridSystemModalLabel">新建<span class='typ'></span></h4>
			</div>
			<div class="modal-body">
				<div class="container-fluid">
					<div class="form-horizontal">
						<div class="form-group ">
							<label for="username" class="col-xs-3 control-label"><span class='typ'></span>名称：</label>
							<div class="col-xs-8 ">
								<input type="text" class="form-control input-sm duiqi" id="name" placeholder="">
							</div>
						</div>
						<div class="form-group">
							<label for="password" class="col-xs-3 control-label"><span class='typ'></span>金额：</label>
							<div class="col-xs-8 ">
								<input type="text" class="form-control input-sm duiqi" id="amount" placeholder="">
							</div>
						</div>
					</div>
				</div>
			</div>
            <div class="modal-footer">
				<button type="button" class="btn btn-xs btn-xs btn-white" data-dismiss="modal">取 消</button>
                <button type="button" class="btn btn-xs btn-xs btn-green" id="submit">提交</button>
			</div>
		</div>
	</div>
</div>
<!--页码块-->
<center>
	<a class="btn btn-xs btn-xs btn-green" onclick='jump("/hotel/finance/exchangePage?page=1")'>#首页
	</a>
	<a class="btn btn-xs btn-xs btn-green" onclick='jump("/hotel/finance/exchangePage?page=${currentPage==1?1:currentPage-1}")'>&lt;上一页
	</a>
	<a class="btn btn-xs btn-xs btn-green" onclick='jump("/hotel/finance/exchangePage?page=${currentPage+1}")'>下一页&gt;
	</a>
</center>
<style>
	.neg{
		color:red;
	}
	.pos{
		color:green;
	}
</style>
<script>
	function setType(typ){
		$('.typ').text(typ==0?'收入':'支出')
	}
	$('#submit').click(function(){
		amount=eval($('#amount').val())
		amount=$('.typ').text()=='收入收入收入'?amount:-amount;
		data={'name':$('#name').val(),'amount':amount}
		$.post('/hotel/finance/executeExchange.do',data,function(str){
			res=eval('(' +str + ')')
			if(res.code==0){
				window.location.href="/hotel/system/mainPage"
			}else{
				alert(res.message)
			}
		})
	})
</script>
</body>
</html>